package cn.pinming.config.shiro;

import cn.pinming.util.EncryptUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.crypto.hash.Sha384Hash;

/**
 * @author wuwanggao
 */
public class PmCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo info) {
        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
        String newPassword = EncryptUtil.hash384Encrypt(String.valueOf(token.getPassword()));
        String oldPassword = (String) this.getCredentials(info);
        return equals(newPassword, oldPassword);
    }
}
